/*
 * Author: Adam Wilford
 * Date Completed: 28 June, 2012
 * Revised: Ben Gentry 6/30/2012
 * 
 * Purpose: This is the primary class for the slot machine GUI. This class
 * contains within it the swing objects used for the Slot Machine.
 * The functionality from the other classes is implented here.
 * 
 */
package slotMachinePackage;

import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import java.util.Random;
import javax.swing.JOptionPane;
import javax.swing.Timer;

//start of the primary SlotMachineInterface class.
public class SlotMachineInterface extends javax.swing.JFrame implements ActionListener{

    public SlotMachineInterface() {

        //timer used to control the changing of the spinners
        timer = new Timer(300, this);
        
        initComponents();
        //initialize all displays at startup
        creditsDisplayUpdate();
        winningsDisplayUpdate();
        spinsDisplayUpdate();
        
        //action listener used for spinner control
        SpinButton.addActionListener(this);
    }
    
    //spinner actionPerformed for spin control
    public void actionPerformed(java.awt.event.ActionEvent evt){
            
        if(evt.getSource() == SpinButton && spins == 0) {
            InsufficientCreditsPopup.showMessageDialog(rootPane,
                    "Insufficient Credits to Spin");
        }
        if(evt.getSource() == SpinButton && spins > 0){
            spins--;
            winnings-=creditsPerSpin;
            currentCredits -= creditsPerSpin;
            tableIndex = generator.nextInt(1000);
            creditsDisplayUpdate();
            spinsDisplayUpdate();
            SoundEffects.SoundEffect.HANDLE.play();
            timer.start();
            SpinButton.setEnabled(false);
        }
        if (evt.getSource() == timer){
            if(!spinnerOneSet)
            {
                setSpinner(spinnerOne, 0);
            }
            if(!spinnerTwoSet)
            {
                setSpinner(spinnerTwo, 1);                
            }
            if(!spinnerThreeSet)
            {
                setSpinner(spinnerThree, 2);                
            }
            
            if(spinnerOneSet && spinnerTwoSet && spinnerThreeSet)
            {
                SpinButton.setEnabled(true);
                timer.stop();
                calcWinnings();
                spinnerOneSet = false;
                spinnerTwoSet = false;
                spinnerThreeSet = false;
            }
          
        }  
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        InsufficientCreditsPopup = new javax.swing.JOptionPane();
        AddCreditsPopup = new javax.swing.JOptionPane();
        HelpDialogPopup = new javax.swing.JDialog();
        HelpOkButton = new javax.swing.JButton();
        jScrollPane7 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        OnExitDialogue = new javax.swing.JDialog();
        OverallWinningsLabel = new javax.swing.JLabel();
        finalWinningsDisplay = new javax.swing.JTextField();
        OnExitExit = new javax.swing.JButton();
        OnExitResume = new javax.swing.JButton();
        OnExitChoicePopup = new javax.swing.JOptionPane();
        OnExitWinningsDisplay = new javax.swing.JOptionPane();
        AddCreditsButton = new javax.swing.JButton();
        ExitButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        creditsRemainingField = new javax.swing.JTextPane();
        jScrollPane2 = new javax.swing.JScrollPane();
        SpinsRemainingField = new javax.swing.JTextPane();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        winningsField = new javax.swing.JTextPane();
        jScrollPane4 = new javax.swing.JScrollPane();
        spinnerOne = new javax.swing.JTextArea();
        jScrollPane5 = new javax.swing.JScrollPane();
        spinnerTwo = new javax.swing.JTextArea();
        jScrollPane6 = new javax.swing.JScrollPane();
        spinnerThree = new javax.swing.JTextArea();
        SpinButton = new javax.swing.JButton();
        HelpButton = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane8 = new javax.swing.JScrollPane();
        lastSpinWinningsDisplay = new javax.swing.JTextPane();
        soundCheckBox = new javax.swing.JCheckBox();

        HelpOkButton.setText("OK");
        HelpOkButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                HelpOkButtonActionPerformed(evt);
            }
        });

        jTextArea1.setColumns(20);
        jTextArea1.setEditable(false);
        jTextArea1.setRows(5);
        jTextArea1.setText("Definition of Buttons\n\nSpin: This button will display 3 randomly \ngenerated numbers. You can only spin\nif you have at least 5 credits, and\ndoing so will subtract 5 credits from \nyour total.\n\nExit: This will safely exit the game and\ndisplay your total earnings.\n\nAdd Credits: This button will allow you to \nadd credits in dollar amounts (you do \nnot need to enter the dollar sign).\n\n\nGoal of the Game\n\nThe goal of the game is to earn as \nmany credits as you can by spinning\nthe slot machine. Each spin requires\n5 credits, and you can earn credits\nby getting certain results from\nthe slot machine.");
        jScrollPane7.setViewportView(jTextArea1);

        javax.swing.GroupLayout HelpDialogPopupLayout = new javax.swing.GroupLayout(HelpDialogPopup.getContentPane());
        HelpDialogPopup.getContentPane().setLayout(HelpDialogPopupLayout);
        HelpDialogPopupLayout.setHorizontalGroup(
            HelpDialogPopupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane7)
            .addGroup(HelpDialogPopupLayout.createSequentialGroup()
                .addGap(155, 155, 155)
                .addComponent(HelpOkButton)
                .addContainerGap(155, Short.MAX_VALUE))
        );
        HelpDialogPopupLayout.setVerticalGroup(
            HelpDialogPopupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, HelpDialogPopupLayout.createSequentialGroup()
                .addComponent(jScrollPane7, javax.swing.GroupLayout.DEFAULT_SIZE, 470, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(HelpOkButton)
                .addContainerGap())
        );

        OverallWinningsLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        OverallWinningsLabel.setText("Overall Winnings:");

        finalWinningsDisplay.setEditable(false);

        OnExitExit.setText("Exit");
        OnExitExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OnExitExitActionPerformed(evt);
            }
        });

        OnExitResume.setText("Resume");
        OnExitResume.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OnExitResumeActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout OnExitDialogueLayout = new javax.swing.GroupLayout(OnExitDialogue.getContentPane());
        OnExitDialogue.getContentPane().setLayout(OnExitDialogueLayout);
        OnExitDialogueLayout.setHorizontalGroup(
            OnExitDialogueLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(OnExitDialogueLayout.createSequentialGroup()
                .addGap(75, 75, 75)
                .addGroup(OnExitDialogueLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(OnExitDialogueLayout.createSequentialGroup()
                        .addComponent(OnExitExit)
                        .addGap(72, 72, 72)
                        .addComponent(OnExitResume))
                    .addGroup(OnExitDialogueLayout.createSequentialGroup()
                        .addComponent(OverallWinningsLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(finalWinningsDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(276, Short.MAX_VALUE))
        );
        OnExitDialogueLayout.setVerticalGroup(
            OnExitDialogueLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(OnExitDialogueLayout.createSequentialGroup()
                .addGap(75, 75, 75)
                .addGroup(OnExitDialogueLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(OverallWinningsLabel)
                    .addComponent(finalWinningsDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(106, 106, 106)
                .addGroup(OnExitDialogueLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(OnExitExit)
                    .addComponent(OnExitResume))
                .addContainerGap(76, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Slot Machine");

        AddCreditsButton.setText("Add Credits");
        AddCreditsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AddCreditsButtonActionPerformed(evt);
            }
        });

        ExitButton.setText("Exit");
        ExitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ExitButtonActionPerformed(evt);
            }
        });

        jLabel1.setText("Credits Available:");

        jLabel3.setText("Spins Remaining:");

        creditsRemainingField.setEditable(false);
        jScrollPane1.setViewportView(creditsRemainingField);

        SpinsRemainingField.setEditable(false);
        jScrollPane2.setViewportView(SpinsRemainingField);

        jLabel2.setText("Overall Winnings: ");

        winningsField.setEditable(false);
        jScrollPane3.setViewportView(winningsField);

        spinnerOne.setColumns(2);
        spinnerOne.setEditable(false);
        spinnerOne.setFont(new java.awt.Font("Zapfino", 1, 48)); // NOI18N
        spinnerOne.setRows(1);
        jScrollPane4.setViewportView(spinnerOne);

        spinnerTwo.setColumns(2);
        spinnerTwo.setEditable(false);
        spinnerTwo.setFont(new java.awt.Font("Zapfino", 1, 48)); // NOI18N
        spinnerTwo.setRows(1);
        jScrollPane5.setViewportView(spinnerTwo);

        spinnerThree.setColumns(2);
        spinnerThree.setEditable(false);
        spinnerThree.setFont(new java.awt.Font("Zapfino", 1, 48)); // NOI18N
        spinnerThree.setRows(1);
        jScrollPane6.setViewportView(spinnerThree);

        SpinButton.setText("Spin");

        HelpButton.setText("Help");
        HelpButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                HelpButtonActionPerformed(evt);
            }
        });

        jLabel4.setText("Winnings Last Spin: ");

        lastSpinWinningsDisplay.setEditable(false);
        jScrollPane8.setViewportView(lastSpinWinningsDisplay);

        soundCheckBox.setSelected(true);
        soundCheckBox.setText("Sound");
        soundCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                soundCheckBoxActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 50, Short.MAX_VALUE)
                            .addComponent(jScrollPane2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(ExitButton)
                        .addGap(18, 18, 18))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(28, 28, 28)
                                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(28, 28, 28)
                                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(AddCreditsButton)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(10, 10, 10)
                                        .addComponent(SpinButton)))
                                .addGap(51, 51, 51)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel4))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
                                    .addComponent(jScrollPane8)))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(HelpButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(soundCheckBox)))
                        .addContainerGap(23, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(5, 5, 5)
                                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addComponent(ExitButton))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(AddCreditsButton)
                            .addComponent(jLabel2)))
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(SpinButton)
                        .addComponent(jLabel4))
                    .addComponent(jScrollPane8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(25, 25, 25)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 36, Short.MAX_VALUE)
                        .addComponent(HelpButton))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(soundCheckBox)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    //member function used to format numbers to monetary format
    private String formatOutput(double d)
    {
        DecimalFormat format = new DecimalFormat();
        format.setMinimumFractionDigits(2);
        format.setMaximumFractionDigits(2);
        return format.format(d);
    }
    
    /*
     * When the exit button is pressed, if there are credits remaining, present
     * the user with an option dialog to choose whether to leave the game 
     * or continue playing. 
     * If the user selects the option to leave the game, display a message 
     * showing their total winnings.
     */
    private void ExitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ExitButtonActionPerformed
        //if there are credits remaining, display option dialog
        if(currentCredits > 0)
        {
            Object[] options = {"Leave the Game", "Resume Playing"};
            OnExitChoicePopup.setOptions(options);
            int choice = OnExitChoicePopup.showOptionDialog(rootPane,
                    "Leave the Game or Resume Playing?",null,JOptionPane.YES_NO_OPTION,
                    JOptionPane.QUESTION_MESSAGE,null,options,null);
            if(choice == 0)
            {
                SoundEffects.SoundEffect.SCREAM.play();
                OnExitWinningsDisplay.showMessageDialog(rootPane,
                        "Overall Winnings: " + formatOutput(winnings));
                this.dispose();
                System.exit(0);
            }
            else if(choice != 1)
            {
                this.dispose();
                System.exit(0);
            }
        }
        //if there are no credits remaining, exit the program
        else
        {
            this.dispose();
            System.exit(0);
        }
    }//GEN-LAST:event_ExitButtonActionPerformed

    
    /*
     * When the AddCredits button is pressed, display a popup prompting the 
     * user to enter the number credits they wish to add. 
     * Check for invalid input (letters, negative numbers)
     * If the input is invalid, clear the entry box and redisplay it/
     * If the input is accepted, add it to the user's credit balance and
     * update the on-screen displays for credits and number of spins available.
     */
    private void AddCreditsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddCreditsButtonActionPerformed
        boolean invalidInput = true;
        String str = "";
        while (invalidInput) {
                try {
                    str = AddCreditsPopup.showInputDialog(rootPane,
                            "Enter Desired Credits To Add: ");
                    if(Double.parseDouble(str) < 0)
                    {
                        throw new Exception();
                    }
                    currentCredits += Double.parseDouble(str);
                    SoundEffects.SoundEffect.DROP.play();
                    invalidInput = false;

                } catch (Exception e) {
                    if(str == null)
                    {
                        invalidInput = false;
                    }
                    else
                    {
                        invalidInput = true;
                    }
                }
        }
        creditsDisplayUpdate();
        spinsDisplayUpdate();
        
    }//GEN-LAST:event_AddCreditsButtonActionPerformed

    /*
     * When the help button is pressed, display a popup listing rules of the 
     * game and user instructions.
     */
    private void HelpButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_HelpButtonActionPerformed
        HelpDialogPopup.setSize(360, 500);
        HelpDialogPopup.setVisible(true);
    }//GEN-LAST:event_HelpButtonActionPerformed

    /*
     * This button is used to close the help dialog popup
     */
    private void HelpOkButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_HelpOkButtonActionPerformed
        HelpDialogPopup.setVisible(false);
    }//GEN-LAST:event_HelpOkButtonActionPerformed

    /*
     * Resume button for the onExit popup that displays when the user hits 
     * the exit button while he has credits remaining
     * Pressing the resume button will return the user to the game.
     */
    private void OnExitResumeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OnExitResumeActionPerformed
        OnExitDialogue.setVisible(false);
    }//GEN-LAST:event_OnExitResumeActionPerformed

    /*
     * Exit button for the onExit popup that displays when the user hits the 
     * exit button while he has credits remaining.
     * Pressing the exit button will dispose the window and exit the process.
     */
    private void OnExitExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OnExitExitActionPerformed
        this.dispose();
        System.exit(0);
    }//GEN-LAST:event_OnExitExitActionPerformed

    private void soundCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_soundCheckBoxActionPerformed
        // TODO add your handling code here:
        if(soundCheckBox.isSelected() == true){
            SoundEffects.SoundEffect.volume = SoundEffects.SoundEffect.Volume.LOW;
        }
        else{
            SoundEffects.SoundEffect.volume = SoundEffects.SoundEffect.Volume.MUTE;
        }
            
    }//GEN-LAST:event_soundCheckBoxActionPerformed

    /**
     * @param args the command line arguments
    /*
     * main function which instantiates and runs the application.
     */
    public static void main(String args[]) {

        SlotMachine.payoutTable();
        SoundEffects.SoundEffect.init();
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new SlotMachineInterface().setVisible(true);
            }
        });
    }
    
    /*
     * member function used to update the text field which shows current credits
     * the user has on the machine.
     */
    public void creditsDisplayUpdate() {
        creditsRemainingField.setText(formatOutput(currentCredits));
    }

    /*
     * Member function which updates the text field which shows the calculated 
     * number of spins the user has remaining.
     */
    public void spinsDisplayUpdate() {
        calcSpins();
        SpinsRemainingField.setText(Integer.toString(spins));
    }

    /*
     * Calculate the number of spins the user has available based upon the
     * number of credits they have in the system.
     */
    public void calcSpins() {
        spins = (int) (currentCredits / creditsPerSpin);
    }
    
    /*
     * Member function that displays updates the text field that displays the
     * user's total winnings.
     */
    public void winningsDisplayUpdate()
    {
        winningsField.setText(formatOutput(winnings));
    }

    /*
     * Member function called by a timer which updates the numbers in the
     * different spin boxes.
     * This function will be called for each of the spinners.
     */
    private void setSpinner(javax.swing.JTextArea spinner, int spinnerNo){ 
        String desired = Integer.toString(tableIndex);
        if(Integer.parseInt(desired) < 10)
        {
            desired = "00" + desired;
        }
        else if((Integer.parseInt(desired) > 10) && (Integer.parseInt(desired) < 100))
        {
            desired = "0" + desired;
        }
        int desiredNumber = Character.getNumericValue(desired.charAt(spinnerNo));
        int spin = generator.nextInt(10);
        if(spin == desiredNumber)
        {
            spinner.setText(Integer.toString(spin));
            switch(spinnerNo)
            {
                case 0:
                    spinnerOneSet = true;
                    break;
                case 1:
                    spinnerTwoSet = true;
                    break;
                case 2: 
                    spinnerThreeSet = true;
                    break;
            }

        }
        else{
            spinner.setText(Integer.toString(spin));
        }
    }
    
     /*
     * Member function that is called when the after the spinners have stopped.
     * It updates the displayed values for winnings in the GUI
     */

    private void calcWinnings(){
        lastSpinWinningsDisplay.setText(formatOutput(SlotMachine.payoutTable[tableIndex]));
        if(SlotMachine.payoutTable[tableIndex] > 0){
            SoundEffects.SoundEffect.COIN.play();
        }
        winnings += SlotMachine.payoutTable[tableIndex];
        winningsDisplayUpdate();
    }
    
    private double currentCredits = 0;//current number of credits available
    private int spins = 0;//number of remaining spins 
    private double creditsPerSpin = 5;//number of credits per spin
    private double winnings = 0;//user's overall winnings
    private int tableIndex = 0;//index for use with the payout table
    Random generator = new Random();
    private Timer timer;//timer used to update the spinners
    private boolean spinnerOneSet = false;
    private boolean spinnerTwoSet = false;
    private boolean spinnerThreeSet = false;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton AddCreditsButton;
    private javax.swing.JOptionPane AddCreditsPopup;
    private javax.swing.JButton ExitButton;
    private javax.swing.JButton HelpButton;
    private javax.swing.JDialog HelpDialogPopup;
    private javax.swing.JButton HelpOkButton;
    private javax.swing.JOptionPane InsufficientCreditsPopup;
    private javax.swing.JOptionPane OnExitChoicePopup;
    private javax.swing.JDialog OnExitDialogue;
    private javax.swing.JButton OnExitExit;
    private javax.swing.JButton OnExitResume;
    private javax.swing.JOptionPane OnExitWinningsDisplay;
    private javax.swing.JLabel OverallWinningsLabel;
    private javax.swing.JButton SpinButton;
    private javax.swing.JTextPane SpinsRemainingField;
    private javax.swing.JTextPane creditsRemainingField;
    private javax.swing.JTextField finalWinningsDisplay;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextPane lastSpinWinningsDisplay;
    private javax.swing.JCheckBox soundCheckBox;
    private javax.swing.JTextArea spinnerOne;
    private javax.swing.JTextArea spinnerThree;
    private javax.swing.JTextArea spinnerTwo;
    private javax.swing.JTextPane winningsField;
    // End of variables declaration//GEN-END:variables
}
